package com.neuedu.web.controller;

import com.neuedu.web.utils.JSONUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 金山
 * 项目：javaweb
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2024/11/1511:01
 */
// @WebServlet(value = "/show_user_info")
@WebServlet( urlPatterns = "/show_user_info")
public class ShowUserInfoController  extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        HttpSession session = request.getSession();
        System.out.println("获取身份的:session.getId() = " + session.getId());
        String userName = (String) session.getAttribute("userName");

        System.out.println("userName = " + userName);
        Map result = new HashMap();
        result.put("userName", userName);

        JSONUtils.write(response, result);

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
